package com.project.intercepter;

import com.project.bean.UserBean;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 顾客拦截器
 */
public class CustomInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        UserBean user = (UserBean) request.getSession().getAttribute("loginUser");

        if (user != null && user.getGrade().equals("顾客")){
            return true;
        }
        response.sendRedirect("/login.html?errInfo=noCustom");
        return false;
    }
}
